blog

Home / DeveloperSection / Blogs / Creating RSS feed for website

Creating RSS feed for website

Anonymous User2178 04-Jun-2012

RSS stands for Really Simple Syndication or it's sometimes referred to as Rich Site Summary.  It's an XML-based content format for distributing news, headlines, content, etc.

Most popular sites news sites and blogs provide RSS feeds for you to subscribe to. All you need is a feed reader to view its contents. You can also create feeds for your own website so your audience can subscribe to them. If you update your content frequently and promote the feed effectively, it can help drive more steady traffic to your website.

There is some specific format from which you can create RSS feed. Let’s take a simple example, how to create RSS feeds for website.

Here I’m just creating a dynamic RSS page for Articles, Blogs and Forums etc. With the help of this a user can bookmark either article sections, blogs section or forums sections.

To create a RSS feeds you start off the RSS file as follows:
<xml version="1.0" encoding="utf-8">
<rss version="2.0">
<channel>

The first two lines specify the XML and RSS version as you can see. The third line opens a ‘channel’ tag. This is what would contain all the information for your channel or website.

 Add these three lines as they are.

<title>MindStick Software Pvt Ltd.</title>

<link>http://www.mindstick.com</link>

<description>MindStick Software Pvt Ltd.</description>

Example:
Code of RSS.aspx Page:

<%@ Page Language="C#" ContentType="text/xml" AutoEventWireup="true" CodeFile="RSS.aspx.cs"
Inherits="LatestArticle_RSS" %>
<asp:repeater id="Repeater1" runat="server">
<HeaderTemplate>
<rss version="2.0">
<channel>
<title>MindStick Software Pvt Ltd.</title>
<link>http://www.mindstick.com</link>
<description>Unleash Your Imagination...</description>
<image>
<url>http://www.mindstick.com/Images/logo.jpg</url>
<title>MindStick Software Pvt Ltd.</title>
<link>http://www.mindstick.com</link>
<description>MindStick Software Pvt Ltd.</description>
<width>134</width>
<height>138</height>
</image>
</HeaderTemplate>
<ItemTemplate>
<item>
<title><%# Server.UrlDecode(RemoveIllegalCharacters(DataBinder.Eval(Container.DataItem, "Title"))) %></title>
<link>http://www.mindstick.com/Articles/<%# DataBinder.Eval(Container.DataItem, "ArticleID") %></link>
<author><%# RemoveIllegalCharacters(DataBinder.Eval(Container.DataItem, "CreatedBy"))%></author>
<pubDate><%# String.Format("{0:R}", DataBinder.Eval(Container.DataItem, "CreationDate"))%></pubDate>
</item>
</ItemTemplate>
<FooterTemplate>
</channel> </rss>
</FooterTemplate>
</asp:repeater>

Code of RSS.aspx.cs Page:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public partial class LatestArticle_RSS : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection sqlConn = new SqlConnection(“Your connection String”);
        sqlConn.Open();
       SqlCommand cmd = new SqlCommand("Write here your command for selecting data from database");
            cmd.Connection = sqlConn;
          Repeater1.DataSource = cmd.ExecuteReader();
       Repeater1.DataBind();
        sqlConn.Close();
    }
  protected string RemoveIllegalCharacters(object input)
    {
        // cast the input to a string 
        string data = input.ToString();
// replace illegal characters in XML documents with their entity references 
        data = data.Replace("&", "&amp;");
        data = data.Replace("\"", "&quot;");
        data = data.Replace("'", "&apos;");
        data = data.Replace("<", "&lt;");
        data = data.Replace(">", "&gt;");
  return data;
    }
}
 

 

This is the complete description on creating RSS feed for website. I hope this article will help you in creating your RSS feeds.


Updated 18-Sep-2014
I am a content writter !

Leave Comment

Comments

Liked By